package com.liusaidh.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
 * @author liusaidh
 * @date 2024/6/4 20:20
 * @description 统一返回结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(description = "返回统一的结果")
public class Result<T> {
    @ApiModelProperty(value = "状态")
    private Integer status;
    @ApiModelProperty(value = "信息")
    private String message;
    @ApiModelProperty(value = "数据")
    private T data;

    private Result(Integer status, String message) {
        this.status = status;
        this.message = message;
    }
    private Result(String message) {
        this.message = message;
    }

    public static <T> Result<T> success(Status status, String message, T data) {
        return new Result<T>(status.getCode(), message, data);
    }

    public static <T> Result<T> success(Status status, String message) {
        return new Result<T>(status.getCode(), message);
    }

    public static <T> Result<T> success(Status status, T data) {
        return new Result<T>(status.getCode(), status.getMessage(), data);
    }

    public static <T> Result<T> success(Status status) {
        return new Result<T>(status.getCode(), status.getMessage());
    }

    public static <T> Result<T> fail(Status status, String message){
        return new Result<T>(status.getCode(),message);
    }

    public static <T> Result<T> fail(Status status){
        return new Result<T>(status.getCode(),status.getMessage());
    }

    public static <T> Result<T> fail(Status status, T date,String message){
        return new Result<T>(status.getCode(),message,date);
    }
}


//    //自定义异常返回的结果
//    public static Result defineError(DefinitionException de) {
//        Result result = new Result();
//        result.setSuccess(false);
//        result.setCode(de.getErrorCode());
//        result.setMsg(de.getErrorMsg());
//        result.setData(null);
//        return result;
//    }
//    //其他异常处理方法返回的结果
//    public static Result otherError(ErrorEnum errorEnum) {
//        Result result = new Result();
//        result.setMsg(errorEnum.getErrorMsg());
//        result.setCode(errorEnum.getErrorCode());
//        result.setSuccess(false);
//        result.setData(null);
//        return result;
//    }

